﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using PdfSharp.Pdf;
using PdfSharp.Drawing;

namespace HelloWorldExample
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();

            var fs = Application.GetResourceStream(
                new Uri("HelloWorldExample;component/Fonts/huxtable.ttf", UriKind.RelativeOrAbsolute)).Stream;

            FontPool.Register(fs, "Huxtable");
        }

        void Button_Click(object sender, RoutedEventArgs e)
        {
            SaveFileDialog d = new SaveFileDialog();
            d.Filter = "PDF file format|*.pdf";

            // Save the document...
            if (d.ShowDialog() == true)
            {
                // Create a new PDF document
                PdfDocument document = new PdfDocument();

                // Create an empty page
                PdfPage page = document.AddPage();
                //page.Contents.CreateSingleContent().Stream.UnfilteredValue;

                // Get an XGraphics object for drawing
                XGraphics gfx = XGraphics.FromPdfPage(page);

                XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);

                // Create a font
                XFont font = new XFont("Huxtable", 20, XFontStyle.Bold, options);

                // Draw the text
                gfx.DrawString(text1.Text, font, XBrushes.Black,
                  new XRect(0, 0, page.Width, page.Height),
                  XStringFormats.Center);




                document.Save(d.OpenFile());
            }
        }

    }
}
